package server.models;

import java.util.ArrayList;

import common.models.*;

public class ChatHistory extends MvcModel {
	
	private static final long serialVersionUID = 6394302256864353742L;
	
	private ArrayList<ChatHistoryItem> allHistory;
	private int userID;
	
	public ChatHistory(int uid) {
		allHistory = new ArrayList<ChatHistoryItem>();
		userID = uid;
	}
	
	public int size() { return allHistory.size(); }
	
	public ChatHistoryItem getItem(int i)
	{
		if (i >= 0 && i < allHistory.size())
			return allHistory.get(i);
		else
			throw new Error("No such chatting history item.");
	}
	
	public void deleteItem(int i) {
		if (i >= 0 && i < allHistory.size())
			allHistory.remove(i);
		else
			throw new Error("No such chatting history item.");
	}
	
	public void sendMessage(int receiver, String content) {
		addItem(userID, receiver, content);
	}
	
	public void receiveMessage(int sender, String content) {
		addItem(sender, userID, content);
	}
	
	private void addItem(int sender, int receiver, String content) {
		allHistory.add(new ChatHistoryItem(sender, receiver, content));
		
	}
}
